
using System;
using System.Collections;
using TienIch.Facade;
using TienIch.Model;
using System.Data;
namespace TienIch.Business
{
	public class CompanyBO : BaseBO
	{
		private CompanyFacade facade = CompanyFacade.Instance;
		protected static CompanyBO instance = new CompanyBO();

		protected CompanyBO()
		{
			this.baseFacade = facade;
		}

		public static CompanyBO Instance
		{
			get { return instance; }
		}
	
		public static DataTable KhoiTaoGrid()
        {
			DataTable dt = new DataTable();
			
			dt.Columns.Add("ID", typeof(int ));
			dt.Columns.Add("Code", typeof(string ));
			dt.Columns.Add("Name", typeof(string ));
			dt.Columns.Add("GiamDoc", typeof(string ));
			dt.Columns.Add("KeToanTruong", typeof(string ));
			dt.Columns.Add("ThuQuy", typeof(string ));
			dt.Columns.Add("DiaChi", typeof(string ));
			dt.Columns.Add("DienThoai", typeof(string ));
			dt.Columns.Add("Fax", typeof(string ));
			dt.Columns.Add("CreatedBy", typeof(string ));
			dt.Columns.Add("CreatedDate", typeof(DateTime ));
			dt.Columns.Add("UpdatedBy", typeof(string ));
			dt.Columns.Add("UpdatedDate", typeof(DateTime ));
			return dt;
		}
		/*
		#region Add and update
		{
			GridView view = sender as GridView;
			CompanyModel model = new CompanyModel();
			
			model.ID =Convert.ToInt32(view.GetRowCellValue(e.RowHandle, colID).ToString());
			model.Code =Convert.ToString(view.GetRowCellValue(e.RowHandle, colCode).ToString());
			model.Name =Convert.ToString(view.GetRowCellValue(e.RowHandle, colName).ToString());
			model.GiamDoc =Convert.ToString(view.GetRowCellValue(e.RowHandle, colGiamDoc).ToString());
			model.KeToanTruong =Convert.ToString(view.GetRowCellValue(e.RowHandle, colKeToanTruong).ToString());
			model.ThuQuy =Convert.ToString(view.GetRowCellValue(e.RowHandle, colThuQuy).ToString());
			model.DiaChi =Convert.ToString(view.GetRowCellValue(e.RowHandle, colDiaChi).ToString());
			model.DienThoai =Convert.ToString(view.GetRowCellValue(e.RowHandle, colDienThoai).ToString());
			model.Fax =Convert.ToString(view.GetRowCellValue(e.RowHandle, colFax).ToString());
			model.CreatedBy =Convert.ToString(view.GetRowCellValue(e.RowHandle, colCreatedBy).ToString());
			model.CreatedDate =Convert.ToDateTime(view.GetRowCellValue(e.RowHandle, colCreatedDate).ToString());
			model.UpdatedBy =Convert.ToString(view.GetRowCellValue(e.RowHandle, colUpdatedBy).ToString());
			model.UpdatedDate =Convert.ToDateTime(view.GetRowCellValue(e.RowHandle, colUpdatedDate).ToString());
			if (view.GetRowCellValue(e.RowHandle, colID) == DBNull.Value) //add new 
			{
				CompanyBO.Instance.Insert(model);
			}
			else //Update
			{
				model.ID = TextUtils.ToInt(view.GetRowCellValue(e.RowHandle, colID).ToString());
				CompanyBO.Instance.Update(model);
			}
		}
		#endregion
		*/
		public static void SaveToTable(DataTable dt)
		{
			DataTable dtRemine;
			dtRemine = dt.GetChanges();
			if (dtRemine != null)
			{
				foreach (DataRow item in dtRemine.Rows)
				{
					CompanyModel model = new CompanyModel();
					
					model.ID =Convert.ToInt32(item["ID"]);
					model.Code =Convert.ToString(item["Code"]);
					model.Name =Convert.ToString(item["Name"]);
					model.GiamDoc =Convert.ToString(item["GiamDoc"]);
					model.KeToanTruong =Convert.ToString(item["KeToanTruong"]);
					model.ThuQuy =Convert.ToString(item["ThuQuy"]);
					model.DiaChi =Convert.ToString(item["DiaChi"]);
					model.DienThoai =Convert.ToString(item["DienThoai"]);
					model.Fax =Convert.ToString(item["Fax"]);
					model.CreatedBy =Convert.ToString(item["CreatedBy"]);
					model.CreatedDate =Convert.ToDateTime(item["CreatedDate"]);
					model.UpdatedBy =Convert.ToString(item["UpdatedBy"]);
					model.UpdatedDate =Convert.ToDateTime(item["UpdatedDate"]);
					if (item["ID"] == DBNull.Value) //add new
					{
						CompanyBO.Instance.Insert(model);
					}
					else //Update
					{
						model.ID = Convert.ToInt32(item["ID"].ToString());
						CompanyBO.Instance.Update(model);
					}
				}
			}
		}
		
		
	}
}
	